package com.sz.app.oss.api.pay;

import com.sz.biz.pay.account.dto.MemberTransactionDto;
import com.sz.biz.pay.account.dto.OrderPaymentDto;
import com.sz.biz.pay.account.service.PaymentService;
import com.sz.biz.pay.account.service.ThirdPayAccountService;
import com.sz.biz.pay.account.service.TransactionService;
import com.sz.biz.pay.transfer.dto.NotifyDataDto;
import com.sz.common.base.dto.ResultDto;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Function: TODO: ADD FUNCTION <br>
 * Author: HeWenBo <br>
 * Date: 2017-11-28 09:52:00
 */
@RestController
@RequestMapping("/api/v1/payment")
@Api(description = " ", tags = "049、账单支付")
public class PaymentController {

    @Autowired
    private TransactionService transactionService;

    @Autowired
    private ThirdPayAccountService thirdPayAccountService;

    @Autowired
    private PaymentService paymentService;

    @ApiOperation(value = "通过客户ID查询第三方账户信息", notes = "查询第三方账户信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "outCustomerId", value = "付款客户id", required = true, dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "inCustomerId", value = "收款客户id", required = true, dataType = "int", paramType = "query")})
    @RequestMapping(value = "/searchPayID", method = {RequestMethod.GET})
    public ResultDto checkCode(@RequestParam int outCustomerId, int inCustomerId) {

        return paymentService.findThirdPayIdByCustomerId(outCustomerId, inCustomerId);
    }

    @ApiOperation(value = "获取交易列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "会员ID",required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "q", value = "查询的关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页 默认第一页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tranType", value = "交易类型", dataType = "String", paramType = "query")})
    @RequestMapping(value = "/searchTransaction/{id}", method = RequestMethod.GET)
    public ResultDto searchTransactionList(@PathVariable String id,
                                           @RequestParam(required = false, defaultValue = "") String q,
                                           @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                           @RequestParam(required = false, defaultValue = "10") int pageSize,
                                           @RequestParam(required = false, defaultValue = "") String beginDate,
                                           @RequestParam(required = false, defaultValue = "") String endDate,
                                           @RequestParam(required = false, defaultValue = "") String tranType) {
        return paymentService.findTransactionList(id, q,pageIndex,pageSize, beginDate, endDate, tranType);
    }

    @ApiOperation(value = "账单交易手续费")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "FuncFlag", value = "功能标志", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "OutCustAcctId", value = "转出子账户", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "OutThirdCustId", value = "转出会员代码", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "OutCustName", value = "转出子账户名称", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "InCustAcctId", value = "转入子账户", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "InThirdCustId", value = "转入会员代码", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "InCustName", value = "转入子账户名称", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "TranAmount", value = "交易金额", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "TranFee", value = "交易费用", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "CcyCode", value = "币种", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "ThirdHtId", value = "订单号", required = true, dataType = "String", paramType = "body"),
            @ApiImplicitParam(name = "Note", value = "备注", required = true, dataType = "String", paramType = "body")})
    @RequestMapping(value = "/transaction/handFee", method = {RequestMethod.POST})
    public ResultDto transactionHandFee(@RequestBody @ApiParam(value = "交易数据", required = true) MemberTransactionDto memberTransactionDto){
        return paymentService.transactionHandFee(memberTransactionDto);
    }

    @ApiOperation(value = "交易支付回调")
    @RequestMapping(value = "/transaction/pay", method = RequestMethod.POST)
    public ResultDto transactionPay(@RequestBody @ApiParam(value = "支付回调", required = true) NotifyDataDto notifyDataDto) {
        if (notifyDataDto != null && notifyDataDto.getSign() != null && notifyDataDto.getOrderid() != null) {
            return paymentService.transactionPay(notifyDataDto);
        }
        ResultDto resultDto = new ResultDto();
        return resultDto;
    }

    @ApiOperation(value = "支付")
    @RequestMapping(value = "/transaction/pingan/pay", method = {RequestMethod.POST})
    public ResultDto OrderPayment(@RequestBody @ApiParam(value = "支付", required = true) OrderPaymentDto orderPaymentDto){
        return paymentService.orderPayment(orderPaymentDto);
    }

    @ApiOperation(value = "获取交易出入金信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "会员ID",required = true, dataType = "string", paramType = "path"),
            @ApiImplicitParam(name = "q", value = "查询的关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "pageIndex", value = "分页 默认第一页", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小", dataType = "int", paramType = "query"),
            @ApiImplicitParam(name = "beginDate", value = "开始日期", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "endDate", value = "结束日期", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "tranType", value = "交易类型", dataType = "String", paramType = "query")})
    @RequestMapping(value = "/findTransaction/{id}", method = RequestMethod.GET)
    public ResultDto findTransaction(@PathVariable String id,
                                           @RequestParam(required = false, defaultValue = "") String q,
                                           @RequestParam(required = false, defaultValue = "1") int pageIndex,
                                           @RequestParam(required = false, defaultValue = "10") int pageSize,
                                           @RequestParam(required = false, defaultValue = "") String beginDate,
                                           @RequestParam(required = false, defaultValue = "") String endDate,
                                           @RequestParam(required = false, defaultValue = "") String tranType) {
        return paymentService.findTransaction(id, q,pageIndex,pageSize, beginDate, endDate, tranType);
    }

    @ApiOperation(value = "通过单号查询付款详情")
    @ApiImplicitParam(name = "orderNo",value = "单号",required = true, dataType = "String",paramType = "path")
    @RequestMapping(value = "/search/{orderNo}", method = RequestMethod.GET)
    public ResultDto searchByOrderNo(@PathVariable String orderNo) {
        return paymentService.findByOrderNo(orderNo);
    }
}
